<?php
class Page{
    
    protected static $_instance = NULL;
    
    public $title ='';
    public $header = '';
    
    public $code = 'index';
    public $id = 0;
    
    public $metaContent = '';
    public $metaDescription ='';
    
    protected $_theme = 'default';
    
    protected function __construct(){}
    
	static public function getInstance(){
        if(is_null(self::$_instance))
           self::$_instance = new self();
        return self::$_instance;   
    }	
    
    /**
     * Set Design theme
     * @param string $name
     */
    public function setTheme($name){
        $this->_theme = $name;
    }
    /**
     * Show page
     */
    public function show(){
	 	$template = new Template();
	 	$template->disableCache();
	 	$template->development =  Application::getConfig()->get('development');
	 	$template->path = Application::getTemplatesPath() . $this->_theme;
	 	$template->page = $this;
	 	$template->blockManager = Blockmanager::getInstance();
	 	Response::put($template->render($template->path . '/layout.php'));
    }
    
 	/**
     * @param string $key
     */
    public function __get($key)
    {
        if($key[0]=='_')
            trigger_error('Trying to access protected property' , E_USER_ERROR);
        
        if(!isset($this->$key))
            return '';
        else 
            return $this->$key;
    }
    /**
     * Get blocks html by place code
     * @param string $placeCode
     * @return string
     */
    public function blocksHtml($placeCode){
    	if(is_null($this->_blockManager))
    		return '';
    		
    	return $this->_blockManager->getBlocksHtml($placeCode);
    }
}